package com.gylang.gylanglog.message;

import com.gylang.common.model.log.SysLogMq;
import com.gylang.common.model.log.SysLoginLogMq;
import com.gylang.gylanglog.domian.SysLog;
import com.gylang.gylanglog.domian.SysLoginLog;
import com.gylang.gylanglog.service.SysLogService;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author gylang,
 * @data 2019/12/4 14:21,
 * @DESC
 */
@Component
public class logMessage {
        @Autowired
        private SysLogService sysLogService;
    @RabbitListener(queuesToDeclare = @Queue("sys_log"))
    public void sysLog(SysLogMq sysLogMq) {

        if (null != sysLogMq) {
            SysLog sysLog = new SysLog();
            BeanUtils.copyProperties(sysLogMq, sysLog);
            sysLogService.saveSysLog(sysLog);
        }
    }

    @RabbitListener(queuesToDeclare = @Queue("sys_login_log"))
    public void sysLoginLogsLog(SysLoginLogMq sysLoginLogMq) {

        if (null != sysLoginLogMq) {
            SysLoginLog sysLoginLog = new SysLoginLog();
            BeanUtils.copyProperties(sysLoginLogMq, sysLoginLog);
            sysLogService.saveLoginLog(sysLoginLog);
        }
    }

}
